<template>
  <div>
    <!-- 搜索框 -->
    <TopFilter ref="form" :list="form" :cols="3" :labelWidth="'85'" @filterChange="changeHandle" />
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      height="auto"
      columnsRef="partPartOutboundPartBreakCheckModal"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectChange"
      selectionType="single"
    ></FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">取 消</el-button>
      <el-button @click.once="closeDrawer(2)" size="small" type="primary" :loading="clickLoading">确定</el-button>
    </div>
  </div>
</template>
<script>
import { searchCheck, getAllUser } from '@/api/part/partOutbound/partBreak';
export default {
  name: '',
  props: ['inventoryNo', 'ptype'],
  data() {
    this.BaseTable = null;
    return {
      form: this.createTopFilterList(),
      fetchApi: searchCheck, // 调用接口
      fetchParams: { xhrAbort: true }, // 调用数据
      columns: this.createTablelist(),
      clickLoading: false,
      selectedRows: []
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  created() {
    this.getDictList();
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '盘点单号',
          fieldName: 'receiptNo',
          initialValue: this.inventoryNo
        },
        {
          type: 'RANGE_DATE',
          label: '盘点日期',
          fieldName: 'innerStr|innerEnd'
        }
      ];
    },
    closeDrawer(type) {
      if (type == 1) {
        this.$emit('close', false);
      } else {
        if (!this.selectedRows.length) {
          return this.closeDrawer(1);
        }
        this.$emit('change', this.selectedRows);
      }
    },
    createTablelist() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '盘点单号',
          dataIndex: 'INVENTORY_NO',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '盘点日期',
          dataIndex: 'INVENTORY_DATE',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '经手人',
          dataIndex: 'HANDLER',
          sorter: true,
          editable: false,
          editType: 'select',
          editItems: [],
          filterType: 'checkbox',
          filterItems: []
        },
        {
          title: '备注',
          dataIndex: 'REMARK',
          sorter: true,
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        }
        // {
        //   title: '锁定人',
        //   dataIndex: 'LOCK_USER',
        //   sorter: true,
        //   editable: false,
        //   editType: 'select',
        //   editItems: [],
        //   filter: true,
        //   filterType: 'checkbox',
        //   filterItems: []
        // }
      ];
    },
    changeHandle(val) {
      console.log(val, 'val');
      let obj = _.cloneDeep(val);
      if (obj.innerStr) {
        obj.innerStr = obj.innerStr.substr(0, 10);
      }
      if (obj.innerEnd) {
        obj.innerEnd = obj.innerEnd.substr(0, 10);
      }
      console.log(obj, 'obj');
      this.fetchParams = Object.assign({}, { sort: 'INVENTORY_NO', order: 'asc' }, obj, { ptype: this.ptype });
    },
    async getDictList() {
      // employeeName翻译
      // this.columns.find(x => x.dataIndex === 'LOCK_USER').filterItems = this.columns.find(x => x.dataIndex === 'LOCK_USER').editItems = (await getAllUser()).data.map(x => ({
      //   text: x.employeeName,
      //   value: x.userId + ''
      // }));
      this.columns.find(x => x.dataIndex === 'HANDLER').filterItems = this.columns.find(x => x.dataIndex === 'HANDLER').editItems = (await getAllUser()).data.map(x => ({
        text: x.employeeName,
        value: x.userId + ''
      }));
    },
    // 选中
    selectChange(rows) {
      this.selectedRows = rows;
    }
  }
};
</script>
